package com.situ.day4;

import org.junit.Test;

import java.lang.String;
import java.util.Scanner;

public class Demo {
    @Test
    public void test1() {
        // int默认值：0
        // double默认值：0.0
        // boolean默认值：false
        // 所有引用数据类型的默认值都是:null
        int num = 3;
        int[] array = new int[3];
        // student可以叫：变量，还可以叫“对象”
        Student student = new Student();
        System.out.println(student.id);// 0
        System.out.println(student.name);// null
        // System.out.println(student1.array);// null

        student.id = 100;
        student.name = "zhangsan";
        student.age = 23;
        student.gender = "男";
        System.out.println(student.id);
        System.out.println(student.name);
    }

    @Test
    public void test12() {
//        4、类是对象的模板，对象是类的具体实例。
//        5、一个类可以创建多个对象：同一个类的不同对象，结构相同，数据不同。
        // String Scanner
        Student student1 = new Student();
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 34;
        student1.study();

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "李四";
        student2.age = 23;
        student2.study();
    }

    @Test
    public void test77() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生的数量： ");
        int count = scanner.nextInt();
        Student[] students = new Student[count];
        for (int i = 0; i < students.length; i++) {
            Student student = new Student();
            System.out.println("请输入id：");
            student.id = scanner.nextInt();
            System.out.println("请输入名字： ");
            student.name = scanner.next();

            students[i] = student;
        }
        // 全部输入完成，再打印素有学生信息
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            // System.out.println(student.toString());
            // 直接打印student对象，默认调用toString()方法
            System.out.println(student);
            // System.out.println(student.id);
            // System.out.println(student.name);
        }

        while (true) {
            System.out.println("输入1、按照学生id搜索");
            System.out.println("输入2、按照学生name搜索");
            System.out.println("输入3、按照学生age搜索");
            System.out.println("输入0、退出搜索");
            int type = scanner.nextInt();
            if (type == 0) {
                System.out.println("退出程序");
                break;
            }
            // 找到了没有，false，因为还没有开始找所以没有找到
            boolean isSearchFound = false;
            switch (type) {
                case 1:
                    System.out.println("请输入要搜索的id：");
                    int id = scanner.nextInt();
                    for (int i = 0; i < students.length; i++) {
                        Student student = students[i];
                        if (id == student.id) {
                            System.out.println(student);
                            isSearchFound = true;
                        }
                    }
                    /*if (!isSearchFound) {
                        System.out.println("没有该信息的学生");
                    }*/
                    if (isSearchFound == false) {
                        System.out.println("没有该信息的学生");
                    }
                    break;
                case 2:
                    System.out.println("请输入要搜索的name：");
                    String name = scanner.next();
                    for (int i = 0; i < students.length; i++) {
                        Student student = students[i];
                        if (name.equals(student.name)) {
                            System.out.println(student);
                            isSearchFound = true;
                            // break;
                        }
                    }
                    if (isSearchFound == false) {
                        System.out.println("没有该信息的学生");
                    }

                    break;
            }
        }

        // 搜索要求：以根据学生name搜索为例，如果找到了符合这个名字的学生，就打印该学生所有信息
        // 如果没有找到这个name的学生，输出“没有该信息的学生”
        System.out.println("-------------------");
    }



    @Test
    public void test99() {
        int[] array1 = new int[3];
        boolean[] array2 = new boolean[3];
        Student[] array3 = new Student[3];

        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }

    @Test
    public void test990() {
        // 在方法中定义的变量是：局部变量。
        // 局部变量必须要初始化：1、赋默认值 2、引用数据类型可以实力话一个对象
        Student student = null;
        // Variable 'student' might not have been initialized
        // init: initialize 初始化
        System.out.println(student);// null
        // java.lang.NullPointerException
        // 当：“null.属性”或者“null.方法”，就会报空指针异常
        System.out.println(student.name);
        // student.study();
    }

    @Test
    public void test66() {
        Student student = new Student();
        System.out.println(student.name);// null
        String name = "";
        System.out.println(name);
        int num = 0;
        System.out.println(num);
    }



}
